/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tces.controller;

import com.tces.model.SubjectOffering;
import com.tces.utils.ConnectionDAO;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author arnolda
 */
public class CollegeDAO  extends ConnectionDAO {

    private static final Logger log = Logger.getLogger(CollegeDAO.class);

    public static List<SubjectOffering> find() throws Exception {
        List<SubjectOffering> collegeList = new ArrayList<SubjectOffering>();
        String sql = "SELECT\n"
                + "c.college_id,\n"
                + "c.college_code,\n"
                + "c.college_name,\n"
                + "FROM\n"
                + "colleges AS c\n"
                + "ORDER BY c.college_code";

        PreparedStatement preparedStatement = getConnectionObject().prepareStatement(sql);
        log.info(preparedStatement.toString());
        ResultSet rs = preparedStatement.executeQuery();
        SubjectOffering college;
        while (rs.next()) {
            college = new SubjectOffering();
            college.setCollegeID(rs.getInt("college_id"));
            college.setCollegeCode(rs.getString("college_code"));
            college.setCollegeName(rs.getString("college_name"));
            collegeList.add(college);
        }
        closeConnection(getConnectionObject());
        return collegeList;
    }
    public static List<SubjectOffering> findCode() throws Exception {
        List<SubjectOffering> collegeList = new ArrayList<SubjectOffering>();
        String sql = "SELECT\n"
                + "c.college_id,\n"
                + "c.college_code,\n"
                + "c.college_name\n"
                + "FROM\n"
                + "colleges AS c\n"
                + "ORDER BY c.college_code";

        PreparedStatement preparedStatement = getConnectionObject().prepareStatement(sql);
        log.info(preparedStatement.toString());
        ResultSet rs = preparedStatement.executeQuery();
        while (rs.next()) {
            log.info(rs.getString("college_code"));
            SubjectOffering subjectOffering = new SubjectOffering();
            subjectOffering.setCollegeID(rs.getInt("college_id"));
            subjectOffering.setCollegeCode(rs.getString("college_code"));
            collegeList.add(subjectOffering);
        }
        closeConnection(getConnectionObject());
        return collegeList;
    }
}
